package com.chensh.gmall.user;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;

@SpringBootApplication
@MapperScan("com.chensh.gmall.user.mapper")
@Configuration
@EnableSwagger2
public class GmallUserApplication {

    /**
     * swagger2  api接口扫描路径
     */
    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.chensh.gmall.user.controller";
    public static final String VERSION = "1.0.0";


    public static void main(String[] args) {
        SpringApplication.run(GmallUserApplication.class, args);
    }

    // swagger2的配置文件，这里可以配置swagger2的一些基本的内容，比如扫描的包等等
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("用户模块")
                        .description("用户模块接口测试")
                        .version(VERSION)
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(Arrays.asList(new ApiKey("token", "token", "header")));
    }

}
